import random
import math
import numpy as np

from pyecharts import Bar
from pyecharts import Scatter3D,Scatter
from pyecharts import Page


#[x1=rand(),x2=rand(),x3=50+40*sin(x1)]
mode = False
#mode = True
def rawdata():
    if mode is  True:
        data = np.load("rawdata.npy")
    else:
        wave = 10 #数据波动范围
        min = 0 #最小
        max = 100 #最大
        cnts = 100 #数据量
        size = 3
        data = np.zeros((cnts,size),np.int16)
        for i in range(cnts):
            data[i][0] =x1= random.randint(min,max)
            data[i][1] =x2= x1**2*(max-2*wave)/max**2+wave+random.randint(-wave,wave)
            #data[i][1] =x2= random.randint(min,max)
            data[i][2] =x3=int( 50+40*math.sin(x1) )+random.randint(-wave,wave)
            #data[i][2] =x3=random.randint(min,max)
            print(data[i])
        np.save("rawdata.npy",data)
    return data


def showraw3d(data):
   page = Page()

   scatter3D = Scatter3D("原始数据散点图",width=600,height=600)
   scatter3D.add("",data,is_visualmap=True)
   page.add(scatter3D)
   page.render("rawdata.html")
   pass

def showret2d(data):
    page = Page()
    scatter = Scatter("PCA数据散点图", width=600,height=600)
    scatter.add("", data[:,0],data[:,1], is_visualmap=True)
    page.add(scatter)
    page.render("pcadata.html")
    pass